 <?php 
  try {  	
  $form = $_POST['form'];
  $JobUid = $form['JOB_UID'];
  $EmployeeId = $form['EMPLOYEE_ID'];
  $PositionId = $form['POSITION_ID'];
  $Boardhiredate = $form['BOARDHIREDATE'];
  $TypeofappointmentId = $form['TYPEOFAPPOINTMENT_ID'];
  $TypeemployeeId = $form['TYPEEMPLOYEE_ID'];
  $JobtitleId = $form['JOBTITLE_ID'];
  $TypepayId = $form['TYPEPAY_ID'];
  $Fte = $form['FTE'];
  $Primaryirn = $form['PRIMARYIRN'];
  $Spreadpay = $form['SPREADPAY'];
  $Otherpay = $form['OTHERPAY'];
  $Locationirn = $form['LOCATIONIRN'];
  $Jobassignment = $form['JOBASSIGNMENT'];
  $JobstatusId = $form['JOBSTATUS_ID'];
  $Terminationdate = $form['TERMINATIONDATE'];
  $Projectterminationdate = $form['PROJECTTERMINATIONDATE'];
  $PayunitId = $form['PAYUNIT_ID'];
  $Unitamount = $form['UNITAMOUNT'];
  $PayplanId = $form['PAYPLAN_ID'];
  $Hoursinday = $form['HOURSINDAY'];
  $Daysinperiod = $form['DAYSINPERIOD'];
  $Numberofpays = $form['NUMBEROFPAYS'];
  $Functions = $form['FUNCTIONS'];
  $Fund = $form['FUND'];
  $Object = $form['OBJECT'];
  $Opu = $form['OPU'];
  $Specialcostcenter = $form['SPECIALCOSTCENTER'];
  $Subject = $form['SUBJECT'];
  $Fundsourcecode1 = $form['FUNDSOURCECODE1'];
  $Fundsourcecode1p = $form['FUNDSOURCECODE1P'];
  $Fundsourcecode2 = $form['FUNDSOURCECODE2'];
  $Fundsourcecode2p = $form['FUNDSOURCECODE2P'];
  $Fundsourcecode3 = $form['FUNDSOURCECODE3'];
  $Fundsourcecode3p = $form['FUNDSOURCECODE3P'];
  $Instructionallevel = $form['INSTRUCTIONALLEVEL'];

  require_once ( PATH_PLUGINS . 'hr' . PATH_SEP . 'class.hr.php');
  $pluginObj = new hrClass ();

  require_once ( "classes/model/HrJobs.php" );

     //if exists the row in the database propel will update it, otherwise will insert.
     $tr = HrJobsPeer::retrieveByPK( $JobUid );
     if ( ! ( is_object ( $tr ) &&  get_class ($tr) == 'HrJobs' ) ) {
       $tr = new HrJobs();
     }

     $tr->setJobUid( $JobUid );
     $tr->setEmployeeId( $EmployeeId );
     $tr->setPositionId( $PositionId );
     $tr->setBoardhiredate( $Boardhiredate );
     $tr->setTypeofappointmentId( $TypeofappointmentId );
     $tr->setTypeemployeeId( $TypeemployeeId );
     $tr->setJobtitleId( $JobtitleId );
     $tr->setTypepayId( $TypepayId );
     $tr->setFte( $Fte );
     $tr->setPrimaryirn( $Primaryirn );
     $tr->setSpreadpay( $Spreadpay );
     $tr->setOtherpay( $Otherpay );
     $tr->setLocationirn( $Locationirn );
     $tr->setJobassignment( $Jobassignment );
     $tr->setJobstatusId( $JobstatusId );
     $tr->setTerminationdate( $Terminationdate );
     $tr->setProjectterminationdate( $Projectterminationdate );
     $tr->setPayunitId( $PayunitId );
     $tr->setUnitamount( $Unitamount );
     $tr->setPayplanId( $PayplanId );
     $tr->setHoursinday( $Hoursinday );
     $tr->setDaysinperiod( $Daysinperiod );
     $tr->setNumberofpays( $Numberofpays );
     $tr->setFunctions( $Functions );
     $tr->setFund( $Fund );
     $tr->setObject( $Object );
     $tr->setOpu( $Opu );
     $tr->setSpecialcostcenter( $Specialcostcenter );
     $tr->setSubject( $Subject );
     $tr->setFundsourcecode1( $Fundsourcecode1 );
     $tr->setFundsourcecode1p( $Fundsourcecode1p );
     $tr->setFundsourcecode2( $Fundsourcecode2 );
     $tr->setFundsourcecode2p( $Fundsourcecode2p );
     $tr->setFundsourcecode3( $Fundsourcecode3 );
     $tr->setFundsourcecode3p( $Fundsourcecode3p );
     $tr->setInstructionallevel( $Instructionallevel );

     if ($tr->validate() ) {
       // we save it, since we get no validation errors, or do whatever else you like.
       $res = $tr->save();
     }
     else {
       // Something went wrong. We can now get the validationFailures and handle them.
       $msg = '';
       $validationFailuresArray = $tr->getValidationFailures();
       foreach($validationFailuresArray as $objValidationFailure) {
         $msg .= $objValidationFailure->getMessage() . "<br/>";
       }
       //return array ( 'codError' => -100, 'rowsAffected' => 0, 'message' => $msg );
     }
    //return array ( 'codError' => 0, 'rowsAffected' => $res, 'message' => '');

    //to do: uniform  coderror structures for all classes
  
  //if ( $res['codError'] < 0 ) {
  //  G::SendMessageText ( $res['message'] , 'error' );  
  //}
  G::Header('location: hrJobsList');   
  
  }
  catch ( Exception $e ) {
    $G_PUBLISH = new Publisher;
    $aMessage['MESSAGE'] = $e->getMessage();
    $G_PUBLISH->AddContent('xmlform', 'xmlform', 'login/showMessage', '', $aMessage );
    G::RenderPage( 'publish', 'blank' );
  }      
   